package main

import (
	"context"
	"study/go-php-grpc/pb"
	"net"
	"log"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
)

const PORT = ":8888"

type server struct {
}

func (s *server) SayHello(ctx context.Context, req *hello_pb.SayHelloRequest) (resp *hello_pb.SayHelloReply, err error) {
	resp = &hello_pb.SayHelloReply{
		Result:"Hello " + req.Content,
	}
	return resp, nil
}

func main() {
	lis, err := net.Listen("tcp", PORT)
	if err != nil {
		log.Fatalln("listen err:", err.Error())
	}
	s := grpc.NewServer()
	hello_pb.RegisterHelloServer(s, &server{})
	if err := s.Serve(lis); err != nil {
		log.Fatalln("grpc err:", err.Error())
	}
	grpclog.Println("start port", PORT)
}
